//
//  CZBasieViewController.swift
//  1215微博终极项目
//
//  Created by chok崋 on 15/12/16.
//  Copyright © 2015年 周卓华. All rights reserved.
//

import UIKit

class CZBasieViewController: UITableViewController,CZVistorViewDelegate {

    var userLogin = CZUserAccount.userLogin
    
    override func loadView() {
        
        userLogin ? super.loadView() : setUpVistorView()
    }
    
    func setUpVistorView ()
    {
        view = vistorView
       
        //设置访客视图的代理
        vistorView.delegate = self
        //添加导航栏的访客视图登录注册按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewResigterBtn")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorLoginViewBtn")
        
        
        if self is CZHomeViewController
        {
            //开启动画
            vistorView.startRotationAnimation()
            //注册系统进入前后台的监听
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackground", name:UIApplicationDidEnterBackgroundNotification , object: nil)
            
            NSNotificationCenter.defaultCenter().addObserver(self, selector:"didBecomeActive" , name: UIApplicationDidBecomeActiveNotification, object: nil)
            
        }else if self is CZMessageViewController
        {
            vistorView.setUpVistorInfo("visitordiscover_image_message", title: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is CZProfileViewController
        {
            vistorView.setUpVistorInfo("visitordiscover_image_message", title: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is CZDiscoverViewController
        {
           vistorView.setUpVistorInfo("visitordiscover_image_profile", title: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
    }
    //退到后台
    func didEnterBackground()
    {
        vistorView.pauseAnimation()
    }
    //进入前台
    func didBecomeActive()
    {
        vistorView.resumeAnimation()
    }
    
    
    //mark:实现视图view的代理方法
    func vistorLoginViewBtn() {
        print(__FUNCTION__)
        
        //创建一个登录的界面
        let vc = CZOauthViewController()
        //包装好导航栏
        let navVc = UINavigationController(rootViewController: vc)
        presentViewController(navVc, animated: true, completion: nil)
    }
    
    func vistorViewResigterBtn() {
        print(__FUNCTION__)
    }
    
    //访客视图的懒加载
    lazy var vistorView:CZVistorView = CZVistorView()
    
    
}
